clear all 
set more off 
set maxvar 15000 
clear matrix


*************
* PANEL A *
*************

	use "$Mydirectory1/3_Output/2_PooledData_analysis.dta", clear 
    keep if baseline_sample==1 
        
    estimates clear   
    
    forval i=1(1)2 {
        gen est_`i'=. 
        gen est_lb_`i'=.
        gen est_ub_`i'=.
    }   
    levelsof decade, local(decades)
        
    *1.
        foreach x of local decades {
            eststo: reg yrsschool_bin log_father_baseline if decade==`x' [pw=wgt_sex_race], robust 
            
            replace est_1 = _b[log_father_baseline] if decade==`x'
            replace est_ub_1 = _b[log_father_baseline]+1.96*_se[log_father_baseline] if decade==`x'
            replace est_lb_1 = _b[log_father_baseline]-1.96*_se[log_father_baseline] if decade==`x'

        }
    *2. 
        foreach x of local decades {
            eststo: reg yrsschool_bin rank_father_baseline if decade==`x' [pw=wgt_sex_race], robust 
            
            replace est_2 = _b[rank_father_baseline] if decade==`x'
            replace est_ub_2 = _b[rank_father_baseline]+1.96*_se[rank_father_baseline] if decade==`x'
            replace est_lb_2 = _b[rank_father_baseline]-1.96*_se[rank_father_baseline] if decade==`x'

        }
    
    * Figure
    bysort decade: keep if _n==1
    keep decade est_*
    reshape long est_ est_lb_ est_ub_, i(decade) j(estimate)
    replace decade= decade+2 if estimate==2

    #delimit ;
    twoway (scatter est_ decade if estimate==1,  msymbol(circle) mcolor(midblue) msize(medium) yaxis(1)) 
           (rcap est_lb_  est_ub_  decade if estimate==1, lpatter(solid) lcolor(midblue) yaxis(1) lwidth(0.5))
           (scatter est_ decade if estimate==2,  msymbol(diamond) mcolor(orange) msize(small) yaxis(2)) 
           (rcap est_lb_  est_ub_  decade if estimate==2, lpatter(solid) lcolor(orange) yaxis(2) lwidth(0.5) ) ,
           
    xti(" " "Decade of respondent's birth") xlabel(1910(10)1970) xscale(range(1905 1975))
    yscale(range(1 3.5)) ylabel(1(0.5)3.5, axis(1)) yti("Coeff. on logged pred. parental fam. inc." " ", axis(1)) 
    ylabel(0.02(.01)0.06, axis(2)) yti(" " "Coeff. on ranked pred. parental fam. inc.", axis(2))
    legend(on ring(0) row(2) pos(2) order(1 "Logged" 3 "Ranked" ))
    xlabel(1910 "1910s" 1920 "1920s" 1930 "1930s" 1940 "1940s" 1950 "1950s" 1960 "1960s" 1970 "1970s", labsize(small) angle(45))
    ;  
    #delimit cr
    graph export "$Mydirectory2/appendix_a/R_yrsschooling_variousfatherincs.pdf", as(pdf) replace


*************
* PANEL B *
*************

	use "$Mydirectory1/3_Output/2_PooledData_analysis.dta", clear 
    keep if baseline_sample==1 
        
    estimates clear 
    
    forval i=1(1)2 {
        gen est_`i'=. 
        gen est_lb_`i' =.
        gen est_ub_`i' =.
    }

    foreach variation in 1 2 {

        if `variation'==1 {
            local dep "log_son_baseline"
            local indep  "log_father_baseline" 
        }
        if `variation'==2 {
            local dep "yrsschool_bin"
            local indep "edu_dad_bin"   
        }

        local samp "& edu_sample==1 [pw=wgt_sex_race_edu]"
        
        levelsof decade, local(decades)
        foreach x of local decades {
            eststo : quietly reg `dep' `indep'  if decade==`x' `samp', robust 
            replace est_`variation' = _b[`indep'] if decade==`x'
            replace est_ub_`variation' = _b[`indep']+1.96*_se[`indep'] if decade==`x'
            replace est_lb_`variation' = _b[`indep']-1.96*_se[`indep'] if decade==`x'
        }

    }

    * Figure
    bysort decade: keep if _n==1
    keep decade est_*
    
    reshape long est_ est_lb_ est_ub_, i(decade) j(estimate)
    replace decade= decade+1.5 if estimate==2   

    #delimit ;
    twoway (scatter est_ decade if estimate==1,  msymbol(circle) mcolor(midblue) msize(medium) yaxis(1)) 
           (rcap est_lb_  est_ub_  decade if estimate==1, lpatter(solid) lcolor(midblue) lwidth(0.5) yaxis(1))
            (scatter est_ decade if estimate==2,  msymbol(diamond) mcolor(teal) msize(small) yaxis(2)) 
           (rcap est_lb_  est_ub_  decade if estimate==2, lpatter(solid) lcolor(teal) lwidth(0.5) yaxis(2))
           ,
    xti(" " "Decade of respondent's birth") xlabel(1910(10)1970) xscale(range(1905 1975))
    ylabel(0(0.25)1, axis(1)) yti("IGE coefficient" " ", axis(1))
    ylabel(0.2(.05)0.4, axis(2)) yti(" " "Coefficient on father education", axis(2))  
    legend(on ring(0) pos(8) rows(2) order(1 "IGE" 3 "Edu-edu"))
    xlabel(1910 "1910s" 1920 "1920s" 1930 "1930s" 1940 "1940s" 1950 "1950s" 1960 "1960s" 1970 "1970s", labsize(small) ) ;  
    #delimit cr
    graph export "$Mydirectory2/appendix_a/baseline_edusample_and_eduedu.pdf", as(pdf) replace


